﻿

create PROCEDURE [dbo].[proc_ConsumableMonth_GetList]
(
	@F_id INT,	
	@page INT,
	@num INT
)


AS

DECLARE @beginRow INT
DECLARE @endRow INT

IF @page=1
BEGIN
	SET @beginRow=0
	SET @endRow=@num
END
ELSE
	BEGIN
		SET @beginRow=@num*(@page-1)
		SET @endRow=@num*@page
	END
	


IF @F_id=0
BEGIN

	SELECT row,* FROM(
    SELECT ROW_NUMBER() OVER (ORDER BY ConsumableDate) AS row,* FROM ConsumableMonth ) AS aaaa WHERE row>@beginRow AND row<=@endRow

END

ELSE
	BEGIN
	SELECT row,* FROM(
    SELECT ROW_NUMBER() OVER (ORDER BY ConsumableDate) AS row,* FROM ConsumableMonth WHERE f_id=@F_id ) AS aaaa WHERE row>@beginRow AND row<=@endRow

	END

RETURN
